import PageConst from './PageConst';
import Zzmx from './../../components/zzmx';

export default {

  defaults(props) {
    return {
      dialogTitle: '',
      showDialog: false,
      showDialogLx: '',
      ...PageConst,
      steps: [],
    }
  },

  //显示明细弹窗
  showModal(ctx) {
    ctx.setState(
      React.addons.update(ctx.getState(), {
        showDialog: {$set: true},
      })
    );
  },

  //隐藏明细弹窗
  hideModal(ctx) {
    ctx.setState(
      React.addons.update(ctx.getState(), {
        showDialog: {$set: false},
      })
    );
  },

  initColoums(ctx, zzmxColoums){
    ctx.setState(
      React.addons.update(ctx.getState(), {
        zzProps: {
          jsxcolumns: {
            $set: zzmxColoums
          }
        },
      }))
  },

  async viewMx(ctx, data, lx){
    switch (lx) {
      case  'zzmx':
        ctx.setState(
          React.addons.update(ctx.getState(), {
            dialogTitle: {
              $set: '资质明细'
            },
            showDialogLx: {
              $set: <Zzmx data={data}/>
            }
          }));
        break;
      default:
        break;
    }
  },

  async timeline(ctx, data){
    const content = await
      ctx.fn.DB.org.info.timeline({Authorization: ctx.getProps().token, ...data}).catch(
        (error) => {
          console.log(error);
        }
      );

    if (content) {
      ctx.setState(
        React.addons.update(ctx.getState(), {
          steps: {
            $set: content
          },
        }));
    }
  },

  async jbxx(ctx, data){

    const content = await ctx.fn.DB.org.info.jbxx({Authorization: ctx.getProps().token, ...data}).catch(
      (error) => {
        console.log(error);
      }
    );

    if (content) {
      ctx.setState(
        React.addons.update(ctx.getState(), {
          org: {$set: content},
        })
      );
    }
  },
  async ryxx(ctx, data){
    const content = await ctx.fn.DB.org.info.ryxx({Authorization: ctx.getProps().token, ...data}).catch(
      (error) => {
        console.log(error);
      }
    );

    if (content) {
      ctx.setState(
        React.addons.update(ctx.getState(), {
          ryProps: {
            jsxdata: {
              data: {$set: content}
            }
          }
        })
      );
    }
  },
  async pctj(ctx, data) {
    const content = await ctx.fn.DB.org.info.pctj({Authorization: ctx.getProps().token, ...data}).catch(
      (error) => {
        console.log(error);
      }
    );
    if (content) {
      let pctjProps = {
        legend: {
          data: []
        },
        series: {
          data: []
        }
      };
      content.map((element) => {
        pctjProps.legend.data.push(element.name);
        pctjProps.series.data.push({name: element.name, value: element.count});
      });
      ctx.setState(
        React.addons.update(ctx.getState(), {
          pctjProps: {
            $merge: pctjProps
          }
        })
      );
    }
  },
  async zzxx(ctx, data){
    const content = await ctx.fn.DB.org.info.zzxx({Authorization: ctx.getProps().token, ...data}).catch(
      (error) => {
        console.log(error);
      }
    );

    if (content) {
      ctx.setState(
        React.addons.update(ctx.getState(), {
          zzProps: {
            jsxdata: {
              data: {$set: content}
            }
          }
        })
      );
    }
  },
  async cxfxx(ctx, data){
    const content = await ctx.fn.DB.org.info.cxfxx({Authorization: ctx.getProps().token, ...data}).catch(
      (error) => {
        console.log(error);
      }
    );

    if (content) {
      ctx.setState(
        React.addons.update(ctx.getState(), {
          cxfProps: {
            jsxdata: {
              data: {$set: content}
            }
          }
        })
      );
    }
  },
  async zjxmxx(ctx, data){
    const content = await ctx.fn.DB.org.info.zjxmxx({Authorization: ctx.getProps().token, ...data}).catch(
      (error) => {
        console.log(error);
      }
    );

    if (content) {
      ctx.setState(
        React.addons.update(ctx.getState(), {
          zjxmProps: {
            jsxdata: {
              data: {$set: content}
            }
          }
        })
      );
    }
  },
  async yjxmxx(ctx, data){
    const content = await ctx.fn.DB.org.info.yjxmxx({Authorization: ctx.getProps().token, ...data}).catch(
      (error) => {
        console.log(error);
      }
    );

    if (content) {
      ctx.setState(
        React.addons.update(ctx.getState(), {
          yjxmProps: {
            jsxdata: {
              data: {$set: content}
            }
          }
        })
      );
    }
  },
}
